package cz.cvut.fel.taskpro.business.imanager;

import cz.cvut.fel.taskpro.business.support.BusinessRuleException;
import cz.cvut.fel.taskpro.business.support.TaskProException;
import cz.cvut.fel.taskpro.data.entity.GroupTaskPro;
import cz.cvut.fel.taskpro.data.entity.Kantor;
import cz.cvut.fel.taskpro.data.entity.Student;
import cz.cvut.fel.taskpro.data.entity.Subject;
import cz.cvut.fel.taskpro.data.entity.TaskProUser;
import cz.cvut.fel.taskpro.data.entity.Team;
import java.io.File;
import java.io.InputStream;
import java.util.List;
import javax.ejb.Local;

/**
 * This interface specify responsible action of business manager, which is
 * responsible for working with user.
 *
 * @author Tom
 * @version 1.0.0. beta @created 11-X-2011 17:51:29
 */
@Local
public interface IUserBusiness {

    /**
     * This method ask dataLayer for all students.
     *
     * @return <code>List</code> of all students in system.
     */
    public List<Student> getStudentsAll();

    /**
     * Thist method ask dataLayer for all users in DB
     *
     * @return <code>List</code> of all users in system
     */
    public List<TaskProUser> getAllUsers();

    /**
     * This method ask dataLayer for all kantors in DB
     *
     * @return <code>List</code> of all kantors in system
     */
    public List<Kantor> getAllKantor();

    /**
     * This method parse data from excel file. Strucrure is followin: 1st login,
     * 2nd password, 3nd name, 4th surname, 5th e-mail, 6th role in system.
     * Method parse these data and retrun list of users.
     *
     * @return <code>List</code> of users who are in file.
     */
    public List<TaskProUser> readExcel(File f) throws BusinessRuleException, TaskProException;

    /**
     * This method ask dataLayer to update user if user is valid. If parameter
     * newPassword is set then password will be changed, otherwise not. If
     * updated user is in state which is no admit by business logic then
     * BusinessRuleExcetion is invoke
     *
     * @param newPassword new passowrd of user, will be hashed. 
     * @param user user, which will be updated. Validation is done.
     */
    public void modifyUser(TaskProUser user, String newPassword) throws BusinessRuleException;

    /**
     * This method reset password for user. New password is randomly generated
     * and user will receive an email notification. If user is in incomatible
     * state then BusinessRuleException is invoke.
     *
     * @param user user who password will be reset. Validation is done.
     *
     */
    public void resetPassword(TaskProUser user) throws BusinessRuleException, TaskProException;

    /**
     * This method ask dataLayer for persist new user based on his state. If
     * password is not specify then is genereated random password. If user is in
     * incompatible state with business logic then BusinessRuleException is
     * invoke. User will receive email notification as well.
     *
     * @param newUser user which will be add to db.
     * @param state type of user. We recognize: Student, Kantor, Admin
     */
    public void addUser(TaskProUser newUser, String state) throws BusinessRuleException, TaskProException;

    /**
     * This method ask dataLayer for persist new user. User have to declare
     * their state. If password is not specify then is genereated random
     * password. If user is in incompatible state with business logic then
     * BusinessRuleException is invoke. User will receive email notification as
     * well.
     *
     * @param users  <code>List</code> of all users which will be added. Validation is done
     */
    public void addUser(List<TaskProUser> users) throws BusinessRuleException, TaskProException;

    /**
     * Metoda vytvori uzivatele, ktere jsou ve vstupnim souboru. Očekávaný
     * formát je CSV, poté požádá datovou vrstu o zápis těchto uživatelů do DB
     *
     * @param fileCSV csv file with users, who will be parsed from
     * @return <code>List</code> of users who will be added to database
     */
    public List<TaskProUser> readCSV(InputStream fileCSV) throws BusinessRuleException, TaskProException;

    /**
     * This method ask businessValidator to validate user to remove and then ask
     * dataLayer to remove user If businessRuleValidator invoke exception then
     * this exception is propagated.
     *
     * @param userToDelete user who will be removed from database
     */
    public void removeUser(TaskProUser userToDelete) throws BusinessRuleException;

    /**
     * This method ask dataLayer to find user based on login
     *
     * @param login by which will be users found. Login is unique.
     * @return founded user based on login.
     */
    public TaskProUser findUserByLogin(String login);


    /**
     * This method ask dataLayer for all students which are part of study group,
     * which teacher learn.
     *
     * @param teacher kantor who teach students. Students who teach this kantor will
     * be found.
     * @return <code>List</code> of students which teacher learn
     */
    public List<Student> getStudenstByKantor(Kantor teacher);

    /**
     * This method ask dataLayer for all users which are members one of group in param.
     * Which means all users which are one of group will be returned. No duplicity.
     * @param groups groups in which are students who will be found. No duplicity.
     * @return <code>List</code> of all users which are members one of groups in param.
     * Which means all users which are one of groups will be returned. No duplicity.
     */
    public List<Student> getStudentsByGroup(List<GroupTaskPro> groups);
  /**
     * This method ask dataLayer for all users which are members one of group in param.
     * Which means all users which are one of group will be returned. No duplicity.
     * @param group group in which are students who will be found.
     * @return <code>List</code> of all users which are members of group in param.
     * Which means all users which are in this group, no duplicity.
     */
    public List<Student> getStudentsByGroup(GroupTaskPro group) throws BusinessRuleException;
    
    /**
     * This method ask dataLayer for all users which are memebers of one of team
     * in param list, without duplicities.
     * @param teams teams by which will be students found. Students who are 
     * member of team will be found.
     * @return all users which are memebers of one of team
     * in param list, without duplicities
     */
    public List<Student> getStudentsByTeam(List<Team> teams);
    /**
     * This method ask dataLayer for all students which are in group which administrate kantor
     * and belong to subject.
     * All param are validate via BusinessRuleValidator, if one of criteria will not pass
     * then businessRuleException is invoke.
     * @param kantor kantor who teach students who will be found. Validation is provided
     * @param subject subject in which are found students member of. Validation is provided.
     * @return <code>List</code> of all students which are in group which administrate kantor
     * and belong to subject.
     */
    public List<Student> getStudentsBySubjectAndKantor(Kantor kantor, Subject subject) throws BusinessRuleException;
    /**
     * This method ask dataLayer for all students which are not in team in specific group.
     * @param group group in which, are students who are not member of team in this group, found.
     * @return <code>List</code> of all students which are not in team in specific group.
     */
    
    public List<Student> getStudentsNotInTeam(GroupTaskPro group) throws BusinessRuleException;
}